<template>
	<qh-page-view title="商品详情">
		<view class="all flex-column-100">
			<scroll-view scroll-y class="scrollView scroll-height">
				<swiper :indicator-dots="indicatorDots" indicator-active-color="var(--primary-color)" :autoplay="autoplay" :interval="interval"
					:duration="duration" circular="true">
					<swiper-item v-if="video_url !=''">
						<video :src="video_url" id="myVideo" muted show-mute-btn autoplay="true" loop='false' class="myvideo" @ended="showBanner"></video>
					</swiper-item>
					<block v-for="(item, index) in banners" :key="index">
						<swiper-item>
							<image :src="item" @tap="seeBig" :data-index="index" class="slide-image" mode="aspectFit"></image>
						</swiper-item>
					</block>
				</swiper>
				<view class="advance-booking">
					<image v-if="image_header" :src="image_header+'goods-advance.png'"></image>
					<view class="boking-txt">
						<view class="img-left">限时预售</view>
						<view class="img-right" v-if="seckillTime>0">
							<view v-if="timeText == 1">距离活动开始还剩：</view>
							<view v-else>距离活动结束还剩：</view>
							<view class="advance-time">
								<view class="time-num">{{seckillTimeArr[0]}}</view>
								<view class="time-txt">天</view>
								<view class="time-num">{{seckillTimeArr[1]}}</view>
								<view class="time-txt">时</view>
								<view class="time-num">{{seckillTimeArr[2]}}</view>
								<view class="time-txt">分</view>
								<view class="time-num">{{seckillTimeArr[3]}}</view>
								<view class="time-txt">秒</view>
							</view>
						</view>
						<view v-if="seckillTime == 0 && loadingOver" class="img-right"><text>该活动已过期</text></view>
					</view>
				</view>
				<view class="goods-amount">
					<view>
						<view>
							<view class="goods-price" v-if="details.advance_type == 2">
								<view>定金<text class="goods-money">￥{{details.earnest_price}}</text>
								</view>
								<view class="goods-gray">总价￥{{details.advance_price}}</view>
							</view>
							<view class="goods-price" v-else>
								<view>预售价<text class="goods-money">￥{{details.advance_price}}</text>
								</view>
							</view>
							<view class="goods-grays" v-if="details.advance_type == 2 && details.arrivea_price > 0">
								定金支付后抵现 ￥{{details.arrivea_price}}</view>
							<view class="goods-grays">已有{{details.reserve_num}}人预定</view>
						</view>

						<view v-if="showShareBtn" class="details-share" @tap="showShare">
							<text class="qh-rt-single qh-rt-fenxiang1-copy share-icon"></text>
							<text class="text-share">分享</text>
						</view>
					</view>
					<view class="goods-name">{{details.goods_name}}</view>
				</view>
				<view class="advance-details">
					<view class="details-list" v-if="details.advance_type == 2">
						<view class="details-left">尾款</view>
						<view class="details-right">{{details.tail_time}}</view>
					</view>
					<view class="details-list">
						<view class="details-left">流程</view>
						<view class="details-right">
							<text v-if="details.advance_type == 2">1.付定金 - 2.付尾款 - 3.发货</text>
							<text v-else>1.付全款 - 2.发货</text>
						</view>
					</view>
					<view class="details-list">
						<view class="details-left">发货时间</view>
						<view class="details-right">{{details.deliver_start_time}} ~ {{details.deliver_end_time}}
						</view>
					</view>
				</view>
				<!-- 配送方式 -->
				<view v-if="delivery_name" class="choice-sku" @tap="clickDeliveryRule">
					<view class="details-list">
						<text class="details-left" style="width: 68rpx;">配送</text>
						<view>
							<view class="fee-flex" :style="delivery_status == 1? 'margin-bottom : 20rpx' : ''">
								<text class="SpecificationsText delivery-title">配送方式</text>
								<text class="SpecificationsText">{{delivery_name}}</text>
								<block v-if="delivery_rule">
									<text v-if="delivery_rule.type==1" class="SpecificationsText">免运费</text>
									<block v-else>
										<text class="SpecificationsText before-line">快递费 ￥</text>
										<text v-if="delivery_rule.type==2||delivery_rule.type==3"
											class="SpecificationsText">{{delivery_rule.list[0].first_fee}}起</text>
										<text v-if="delivery_rule.type==4" class="SpecificationsText">{{delivery_rule.list[0].unified_fee}}起</text>
									</block>
									<view class="Specifications-img">
										<image mode="aspectFit" src="/static/images/arrow-1.png"></image>
									</view>
								</block>
							</view>
							<view v-if="delivery_status == 1">
								<text class="SpecificationsText delivery-title">配送费</text>
								<text class="SpecificationsText">单笔消费满{{delivery_cost}}元免运费</text>
							</view>
						</view>
					</view>
				</view>
				<view class="choice-sku" @tap="Specifications">
					<view class="details-list">
						<view class="details-left">选择</view>
						<view class="details-right">{{details.attribute_state==2?'规格、':''}} 数量</view>
					</view>
				</view>
				<!-- 评价 -->
				<view class="CommentStyle bg" @tap="toComment">
					<view class="Comment-nav">
						<text class="Comment-nav-words">商品评价 ({{total}})</text>
						<view class="Specifications-img specifications-image">
							<image mode="aspectFit" src="/static/images/arrow-1.png"></image>
						</view>
					</view>
					<view class="content">
						<view class="Comment-detail" v-if="total>0">
							<view class="userInfo">
								<image :src="commentInfo[0].avatar" mode="aspectFit" class="userImage"></image>
								<text class="nickName">{{commentInfo[0].nickname}}</text>
							</view>
							<view class="Comment-con">
								<text class="Comment-con-words">{{commentInfo[0].content}}</text>
								<view class="Comment-con-img">
									<image v-for="(item, i) in commentInfo[0].evaluate_img" :key="i" :src="item" mode="aspectFit" @tap.stop="scaleBig"
										:data-index="i"></image>
								</view>
							</view>
						</view>
						<view class="content-title" v-else>
							<text class="Comment-content">该商品暂无评价~</text>
						</view>
					</view>
				</view>
				<view class="goods-particulars" v-if="display_detail == 1">
					<view class="particulars-title">商品详情</view>
					<view class="wxParse">
						<jyf-parser :html="article_desc"></jyf-parser>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- 规格 -->
		<view class="choose-sku-container" v-if="alertToggle">
			<view class="choose-sku-model" @tap="closeAlert" @longtap="closeAlert" @touchmove="closeAlert"></view>
			<view class="choose-sku-box" :style="skuBoxStyle">
				<text class="qh-rt-single qh-rt-a-ziyuan1 alert-close-icon" @tap.stop="closeAlert"></text>
				<view class="choose-sku-title-box">
					<view class="choose-sku-goods-image">
						<image mode="aspectFit" lazy-load="true" :src="skuImg" @tap="seeSkuBig"></image>
					</view>
					<view class="choose-sku-goods-title-right-box">
						<view class="choose-sku-price-box">
							<block>
								<text class="choose-sku-price" v-if="details.advance_type == 1">预售价￥{{skuPrice}}</text>
								<text class="choose-sku-price" v-else>定金￥{{skuPrice}}</text>
								<text class="choose-sku-all" v-if="details.advance_type == 2">总价 ￥{{allPrice}}</text>
							</block>
						</view>
						<view class="choose-sku-goods-stock" v-if="details.advance_type == 2 && arrivePrice > 0">定金支付后抵现
							￥{{arrivePrice}}</view>
						<view class="choose-sku-goods-stock">库存 {{skuNum}}</view>
					</view>
					<view class="choose-sku-attr-box" v-if="details.attribute_state==2">
						<view class="choose-sku-attr" v-for="(item, pIndex) in skuDetailList&&skuList" :key="pIndex">
							<view class="choose-sku-attr-name">{{item.name}}</view>
							<view class="choose-sku-list-box">
								<block v-for="(list, cIndex) in item.list" :key="cIndex">
									<block v-if="list.status==1">
										<view :class="'choose-sku-list-name' + (skuSelectIndex[pIndex]==cIndex?' choose-sku-select':'')" @tap="checkSku"
											:data-p-index="pIndex" :data-c-index="cIndex">{{list.name}}
										</view>
									</block>
									<view v-else class="choose-sku-list-name choose-sku-disable-check">{{list.name}}
									</view>
								</block>
							</view>
						</view>
					</view>
					<view class="choose-sku-change-con" :style="details.attribute_state==2?'border-top:1rpx solid #eee;':'border:none'">
						<view class="choose-sku-change-tag">
							<text>数量</text>
							<text class="choose-sku-change-tag-tip" v-if="details.restrict_num!=null">（限购{{details.restrict_num}} 件）</text>
						</view>
						<view class="choose-sku-change-box">
							<text class="choose-sku-change-rise" v-if="details.rise_num!=null">{{details.rise_num}}件起购</text>
							<view class="choose-sku-change border">
								<text class="qh-rt-single qh-rt-a-zu4424 choose-sku-change-icon" @click.stop="jian"></text>
								<view class="choose-sku-num">
									<input min="1" type="number" @blur="blurNum" :value="buyNum" placeholder="1" placeholder-class="choose-sku-p"></input>
								</view>
								<text class="qh-rt-single qh-rt-jia1 choose-sku-change-icon" @click.stop="jia"></text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 底部按钮 -->
		<view class="footer" :style="footerStyle">
			<block v-if="customer_service==1||customer_service=='1'">
				<view class="kefu" @tap.stop="calltophone">
					<image src="/static/images/kefu.png"></image>
					<text>电话</text>
				</view>
			</block>
			<block v-else>
				<!-- #ifdef MP-WEIXIN -->
				<button class="kefu" open-type="contact" @contact="handleContact">
					<image src="/static/images/kefu.png"></image>
					<text>客服</text>
				</button>
				<!-- #endif -->
			</block>
			<view class="sc" @tap="dosc" :data-type="collect_state">
				<image :src="collect_img"></image>
				<text>{{collect_text}}</text>
			</view>
			<view class="details-btn" v-if="Stock>0 ">
				<view class="times-btn">
					<view>{{details.advanceEndTime ? details.advanceEndTime : ''}} 预售结束</view>
					<view>{{details.deliver_time ? details.deliver_time : ''}} 开始配送</view>
				</view>
				<login-and-register v-if="seckillTime > 0 && (!userInfo.vid && userInfo.platform_type == 2)" :type="userInfo.login_state == 1 ? 4 : 3"
					@success="registerSuccess">
					<view>{{details.advance_type == 1 ? '付全款' : '支付定金'}}</view>
				</login-and-register>
				<view v-if="seckillTime > 0 && ((userInfo.vid && userInfo.platform_type == 2) || (userInfo.platform_type == 1))" @tap="buynow">
					{{details.advance_type == 1?'付全款':'支付定金'}}
				</view>
				<view v-if="seckillTime == 0 && loadingOver">活动结束</view>
			</view>
			<view class="details-btn" v-else>
				<view class="times-btn">
					<view>{{details.advance_end_time ? details.advance_end_time : ''}} 预售结束</view>
					<view>{{details.deliver_start_time ? details.deliver_start_time : ''}} 开始配送</view>
				</view>
				<view>库存不足</view>
			</view>
		</view>
		<!-- 配送规则 -->
		<view class="choose-sku-container choose-sku-container-index" v-if="showDeliveryRule">
			<view class="choose-sku-model" @tap="clickDeliveryRule" @longtap="clickDeliveryRule" @touchmove="clickDeliveryRule"></view>
			<view class="choose-sku-box choose-sku-box-bottom" :style="skuBoxStyle">
				<text class="qh-rt-single qh-rt-a-ziyuan1 alert-close-icon" @tap.stop="clickDeliveryRule"></text>
				<view class="model-title">运费计价说明</view>
				<view class="delivery-content">
					<view>
						<text>当前商品仅支持以下地区快递发货，如有疑问请联系商家</text>
					</view>
					<view v-for="(item, c) in delivery_rule.list" :key="c">
						<text>{{item.area_name}}，</text>
						<text v-if="delivery_rule.type==1">免运费</text>
						<text v-if="delivery_rule.type==2">首{{item.first_num*1}}件{{item.first_fee}}元，每续{{item.append_num*1}}件{{item.append_fee}}元。</text>
						<text v-else-if="delivery_rule.type==3">首{{item.first_num*1}}kg{{item.first_fee}}元，每续{{item.append_num*1}}kg{{item.append_fee}}元。</text>
						<text v-else-if="delivery_rule.type==4">统一运费{{item.unified_fee}}元。</text>
					</view>
					<view v-if="delivery_status == 1">单笔消费满{{delivery_cost}}元免运费</view>
				</view>
			</view>
		</view>
		<!-- 引入分享模板 -->
		<share v-if='isShowShare' @close='closeShowShare' :share='share'></share>
	</qh-page-view>
</template>

<script>
	var app = getApp().globalData;
	import share from '@/components/share.vue'
	export default {
		components: {
			share,
		},
		data() {
			return {
				video_url: "",
				autoplay: true,
				circular: true,
				detailsName: "商品名称",
				subheading: "副标题",
				unitPrice: "100.00",
				originalPrice: "200.00",
				Deal: "0",
				interval: 3000,
				duration: 1000,
				loadingOver: false,
				language: [],
				nav: [{
					navItem: "商品详情"
				}, {
					navItem: "评价"
				}],
				navOn: 0, //当前选中
				navCon: true,
				evaluateLen: 0, //评价条数
				Stock: 1000, //库存
				buyNum: 1, //购买数量
				allPrice: "", //预售价格
				alertToggle: false,
				isScroll: true, //弹框出现  静止页面滚动
				collect_img: "/static/images/sc.png", //收藏
				collect_state: 0, //是否收藏  0未收藏 1已收藏
				collect_text: "收藏",
				discount: 0,
				goods_id: '0',
				ischecknum: false,
				specifications: "规格",
				company: "单位",
				skuSelectIndex: [],
				selectSkuDetailId: -1,
				shopItemInfo: {},
				selectArr: [],
				skuImg: '',
				desc: "",
				customer_service: 2, // 1.电话客服 2.微信客服
				share: {
					maskShare: false,
					//分享弹窗
					maskHidden: false, //海报图片,
					type: 4,
					data: ''
				},
				vip: null,
				total: 0,
				delivery_set: [0, 0, 0], //配送方式
				delivery_rule: null, //配送规则
				showDeliveryRule: "",
				seckillTimeArr: "",
				seckillTime: 0,
				timeText: "",
				skuList: "",
				skuPrice: "",
				arrivePrice: "",
				skuNum: "",
				details: {},
				skuDetailList: "",
				banners: "",
				not_banners: 0,
				delivery_name: "",
				commentInfo: "",
				article_desc: "",
				display_detail: 0,
				isShowShare: false,
				isShowShareData: {
					guide_id: null,
					goods: "",
					goods_img: '',
					goods_id: '0'
				},
				delivery_status: 0,
				delivery_cost: '',
				isShowDialog: false,
				isGetPhone: false, // 是否获取手机号
				userInfo: {}, // 用户信息
				register_phone: '', // 注册手机号
				showShareBtn: true,

				browse_duration: 0, //浏览时长
				browseTimer: null, //浏览计时器
			};
		},
		computed: {
			image_header() {
				return this.$store.image_header
			},
			footerStyle() {
				let h = this.$store.bottomHeight + 110
				return 'height:' + h + 'rpx;padding-bottom:' + this.$store.bottomHeight + 'rpx';
			},
			skuBoxStyle() {
				return 'bottom:' + (this.$store.bottomHeight + 110) + 'rpx';
			},
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		async onLoad(options) {
			// #ifdef MP-ALIPAY
			if (JSON.stringify(options) == '{}') {
				options = my.getLaunchOptionsSync().query;
			}
			// #endif
			console.log('页面参数：', options)
			await this.$onLaunched;

			// #ifdef MP-ALIPAY
			this.showShareBtn = app.XcxData.appid == app.XcxData.tempAppId ? false : true;
			// #endif

			// #ifdef MP-WEIXIN
			if (!options.id) {
				options = getApp().globalData.getOnLaunchParam(options);
			}
			// #endif

			if (options && options.store_id) {
				this.$store.store_id = options.store_id;
			}
			this.goods_id = options.id;
			this.userInfo = {
				...app.XcxData.userInfo
			};
			this.getDetail();
		},
		onShow() {
			if (this.browse_duration > 0) {
				this.browseTimer = setInterval(() => {
					this.browse_duration++;
				}, 1000)
			}
		},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide() {
			clearInterval(this.browseTimer);
		},

		onUnload() {
			clearInterval(this.seckillTimer);
			clearInterval(this.browseTimer);
			app.addVisitGoodsRecord({
				goods_id: this.details.goods_id,
				browse_duration: this.browse_duration,
			})
		},
		onShareAppMessage(res) {
			var path = '/pages/index/advanceDetails/advanceDetails?id=' + this.goods_id + '&store_id=' + this.$store.store_id + '&share_uid=' + app.XcxData
				.userInfo.uid;
			return {
				title: this.details.goods_name,
				path: path,
				imageUrl: this.goods_img,
			};
		},
		methods: {
			//会员注册成功
			registerSuccess() {
				this.userInfo = {
					...app.XcxData.userInfo
				};
				this.buynow();
			},
			closeShowShare() {
				this.setData({
					isShowShare: false,
					share: {
						maskShare: false
					},
				})
			},
			//显示运费规则
			clickDeliveryRule: function() {
				if (this.delivery_rule) {
					this.setData({
						showDeliveryRule: !this.showDeliveryRule
					});
				}
			},
			//预售倒计时
			reCountSeckillTime: function() {
				this.loadingOver = false
				uni.showLoading({
					title: '加载中1...',
					// #ifndef MP-ALIPAY
					mask: true,
					// #endif
				})
				var seckillTimeArr = ['', '', '', ''];
				this.seckillTimer = null;
				var seckillTime = 0;
				var timeText = 0;
				this.setData({
					seckillTimeArr: seckillTimeArr,
					//秒杀倒计时显示数组
					seckillTime: seckillTime //秒杀倒计时
				});

				if (this.details.advance_end_time) {
					seckillTime = this.details.advance_end_time;
					var startTime = this.details.advance_start_time;
					var timestamp = Date.parse(new Date());
					timestamp = timestamp / 1000;
					console.log("当前时间戳为：" + timestamp);

					if (timestamp - startTime < 0) {
						seckillTime = startTime - timestamp;
						timeText = 1;
					} else {
						seckillTime = seckillTime - timestamp;
						timeText = 2;
					}

					this.seckillTimer = setInterval(() => {
						seckillTime--;

						if (seckillTime == 0) {
							this.loadingOver = true
							clearInterval(this.seckillTimer);
							seckillTimeArr = ['', '', '', ''];
							this.setData({
								seckillTimeArr: seckillTimeArr,
								seckillTime: seckillTime,
								timeText: timeText
							});
						} else {
							this.loadingOver = false
							let arr = getApp().globalData.getDayHis(seckillTime * 1000);

							this.setData({
								seckillTimeArr: arr,
								seckillTime: seckillTime,
								timeText: timeText
							});
						}
					}, 1000);
				}
				uni.hideLoading();
			},

			//点击分享
			showShare: function(e) {

				this.isShowShareData.groupData = {
					text: '距结束：',
					status: 1,
					time: this.seckillTimeArr,
				}

				this.setData({
					share: {
						maskShare: true,
						maskHidden: false,
						data: this.isShowShareData,
						type: 4,
					},
					isShowShare: true,
				});
			},

			blurNum: function(e) {
				var num = e.detail.value;
				var rise_num = parseFloat(this.details.rise_num);

				if (num == '' || num < 0 || this.details.rise_num != null && num < rise_num) {
					this.setData({
						buyNum: this.details.rise_num ? this.details.rise_num : 1
					});
				} else {
					var skuNum = this.skuNum;

					if (num > skuNum) {
						num = skuNum;
					}

					if (this.details.restrict_num != null && num > parseFloat(this.details.restrict_num)) {
						num = this.details.restrict_num;
					}

					this.setData({
						buyNum: num
					});
				}
			},
			cratedSku: function() {
				var that = this;
				var skuDetailList = this.skuDetailList;
				var shopItemInfo = {};

				for (var i in skuDetailList) {
					shopItemInfo[skuDetailList[i].sku_id_list] = skuDetailList[i];
				}

				this.setData({
					shopItemInfo: shopItemInfo
				});
				this.checkItem();
			},
			checkSku: function(e) {
				var pIndex = e.currentTarget.dataset.pIndex;
				var cIndex = e.currentTarget.dataset.cIndex;
				var that = this;
				var skuList = this.skuList;
				var skuSelectIndex = this.skuSelectIndex;
				var selectArr = this.selectArr;

				if (selectArr[pIndex] != skuList[pIndex].list[cIndex].id) {
					selectArr[pIndex] = skuList[pIndex].list[cIndex].id;
					skuSelectIndex[pIndex] = cIndex;
				} else {
					selectArr[pIndex] = 0;
					skuSelectIndex[pIndex] = -1;
				}

				this.setData({
					selectArr: selectArr,
					skuSelectIndex: skuSelectIndex
				});
				this.checkItem();
			},
			checkItem: function() {
				var that = this;
				var option = this.skuList;
				var selectArr = this.selectArr;
				var result = []; //定义数组存储被选中的值

				for (var i in option) {
					result[i] = selectArr[i] ? selectArr[i] : 0;
				}

				for (var i in option) {
					var last = result[i];

					for (var k in option[i].list) {
						result[i] = option[i].list[k].id;
						option[i].list[k].status = this.isMay(result); //在数据里面添加字段isShow来判断是否可以选择
					}

					result[i] = last;
				}

				this.setData({
					skuList: option
				});
				var selectArr = this.selectArr;

				if (selectArr.indexOf(0) == -1) {
					var id_list = selectArr.join(','); //skuImg

					var sku = this.shopItemInfo[id_list];
					var price = 0;

					if (this.details.advance_type == 1) {
						price = sku.advance_price; //预售价格
					} else {
						price = sku.earnest_price; //预售定金
					}

					this.setData({
						selectSkuDetailId: sku.sku_id,
						skuPrice: price,
						allPrice: sku.advance_price,
						arrivePrice: sku.arrive_price,
						skuNum: parseInt(sku.surplus_num),
						skuImg: sku.goods_img
					});
				} else {
					this.setData({
						selectSkuDetailId: -1,
						skuPrice: this.details.advance_type == 1 ? this.details.advance_price : this.details
							.earnest_price,
						allPrice: this.details.advance_price,
						arrivePrice: this.details.arrive_price,
						skuNum: this.details.surplus_num,
						skuImg: this.details.goods_img
					});
				}
			},
			isMay: function(result) {
				for (var i in result) {
					if (result[i] == 0) {
						return 1;
					}
				}

				var sku = this.shopItemInfo[result];

				if (sku && sku.advance_num >= 1) {
					return 1;
				} else {
					return 0;
				}
			},
			//拨打电话
			calltophone: function() {
				var phone = this.phone;

				if (!phone) {
					uni.showToast({
						title: '商家未设置门店电话',
						icon: 'none'
					});
					return;
				}

				uni.makePhoneCall({
					phoneNumber: phone //仅为示例，并非真实的电话号码

				});
			},

			// 内容切换  
			navItem(e) {
				var id = e.currentTarget.id;
				var navCon = this.navCon;
				this.setData({
					navOn: id,
					navCon: !navCon
				});
			},

			// 加
			jia() {
				if (this.buyNum < (this.details.attribute_state == 2 ? this.skuNum : this.Stock)) {
					var buyNum = this.buyNum;
					var Stock = this.Stock;
					buyNum++;

					if (buyNum >= Stock) {
						buyNum = Stock;
					}

					if (this.details.restrict_num != null && buyNum > parseFloat(this.details.restrict_num)) {
						buyNum = this.details.restrict_num;
					}

					this.setData({
						buyNum: buyNum
					});
				}
			},

			// 减
			jian() {
				var buyNum = this.buyNum;

				if (buyNum > 1) {
					buyNum--;
				}
				if (this.details.rise_num != null && buyNum < parseFloat(this.details.rise_num)) {
					buyNum = this.details.rise_num;
				}

				this.setData({
					buyNum: buyNum
				});
			},

			// 规格
			Specifications(e) {
				this.setData({
					alertToggle: true,
					isScroll: false,
					ischecknum: true
				});
			},

			//关闭弹框
			closeAlert() {
				this.setData({
					alertToggle: false,
					isScroll: true,
					ischecknum: 0
				});
			},

			dosc: function(e) {
				// console.log(e);
				var collect_state = e.currentTarget.dataset.type;
				var details = this.details;
				var that = this;

				if (collect_state == 0) {
					//未收藏 -- 添加收藏
					getApp().globalData.sendRequest({
						url: '/Collect/addCollect',
						type: "post",
						data: {
							goods_id: details.goods_id,
							activity_id: details.id,
							type: 4
						},
						success: function(res) {
							if (res.status == 1) {
								uni.showToast({
									title: res.msg,
									icon: 'success',
									// #ifndef MP-ALIPAY
									duration: 1500,
									// #endif
									mask: true
								});
								that.setData({
									collect_state: 1
								});
								that.handleCollect();
							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none',
									duration: 1500,
									mask: true
								});
							}
						}
					});
				} else {
					//已收藏 -- 删除收藏
					getApp().globalData.sendRequest({
						url: '/Collect/cancelCollect',
						type: "post",
						data: {
							goods_id: details.goods_id,
							activity_id: details.id,
							type: 4
						},
						success: function(res) {
							if (res.status == 1) {
								uni.showToast({
									title: res.msg,
									icon: 'success',
									// #ifndef MP-ALIPAY
									duration: 1500,
									// #endif
									mask: true
								});
								that.setData({
									collect_state: 0
								});
								that.handleCollect();
							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none',
									duration: 1500,
									mask: true
								});
							}
						}
					});
				}
			},

			//收藏
			handleCollect() {
				var collect_state = this.collect_state;

				if (collect_state == 1) {
					this.setData({
						collect_img: "/static/images/sc2.png",
						collect_text: '已收藏',
						collect_state: 1
					});
				} else {
					this.setData({
						collect_img: "/static/images/sc.png",
						collect_text: '收藏',
						collect_state: 0
					});
				}
			},

			//查看大图
			seeBig: function(e) {
				var index = parseInt(e.currentTarget.dataset.index);
				uni.previewImage({
					current: this.banners[index],
					urls: this.banners // 需要预览的图片http链接列表

				});
			},
			seeSkuBig() {
				uni.previewImage({
					current: this.skuImg,
					urls: [this.skuImg] // 需要预览的图片http链接列表

				});
			},
			getDetail() {
				uni.showLoading({
					title: '加载中...',
					// #ifndef MP-ALIPAY
					mask: true,
					// #endif
				});

				getApp().globalData.sendRequest({
					url: '/Goods/advanceGoods',
					type: "post",
					data: {
						id: this.goods_id
					},
					success: (res) => {
						uni.hideLoading();

						if (res.status == 1) {
							if (!this.$store.store_id) {
								this.$store.store_id = res.data.store_id;
							}
							let price = 0;

							if (res.data.advance_type == 1) {
								price = res.data.advance_price; //预售价格
							} else {
								price = res.data.earnest_price; //预售定金
							}

							this.setData({
								details: res.data,
								video_url: res.data.video_url, //轮播视频url
								skuImg: res.data.goods_img, //商品弹框图片
								skuNum: parseFloat(res.data.surplus_num), //预售库存
								skuPrice: price,
								arrivePrice: res.data.arrive_price,
								allPrice: res.data.advance_price,
								delivery_set: res.delivery_set,
								delivery_rule: res.delivery_rule ? res.delivery_rule : null,
								collect_state: res.data.collect_state,
								buyNum: res.data.rise_num != null ? res.data.rise_num : 1,
								isShowShareData: {
									guide_id: res.guide_id ? res.guide_id : null,
									goods: res.data,
									goods_img: res.data.goods_img ? res.data.goods_img : '',
									goods_id: this.goods_id,
								},
								delivery_status: res.delivery_status,
								delivery_cost: res.delivery_cost,
								detailsName: res.data.goods_name
							});

							if (res.skuDetailList && res.skuList) {
								var skuSelectIndex = [];
								var selectArr = [];

								for (var i = 0; i < res.skuList.length; i++) {
									skuSelectIndex.push(-1);
									selectArr.push(0);
								}

								this.setData({
									skuList: res.skuList,
									skuDetailList: res.skuDetailList,
									skuSelectIndex: skuSelectIndex,
									selectArr: selectArr,
									skuImg: res.data.goods_img
								});
								this.cratedSku();
							}

							if (res.data.details) {
								setTimeout(() => {
									this.article_desc = res.data.details;
								}, 200);
								this.setData({
									display_detail: 1 // 图文详情

								});
							}

							if (res.data.banners) {
								if (res.data.banners.length) {
									this.setData({
										banners: res.data.banners
									});
								} else {
									var banners = [res.data.goods_img];
									this.setData({
										banners: banners
									});
								}
								if (this.video_url) {
									this.autoplay = false
								} else {
									this.autoplay = true
								}
							} else {
								this.setData({
									not_banners: 1
								});
							}

							if (res.delivery_set) {
								var delivery_name = [];

								for (var i = 0; i < res.delivery_set.length; i++) {
									if (res.delivery_set[i].data == 1) {
										delivery_name.push(res.delivery_set[i].name);
									}
								}

								this.setData({
									delivery_name: delivery_name.join(' & ')
								});
							}
							this.browseTimer = setInterval(() => {
								this.browse_duration++;
							}, 1000)
							this.handleCollect();
							this.reCountSeckillTime();
							this.getcommentList();
						} else {
							uni.showModal({
								title: '提示',
								content: res.msg,
								complete: function(res) {
									uni.navigateBack({
										delta: 1
									});
								}
							});
						}
					}
				});
			},
			//轮播视频加载完触发事件
			showBanner() {
				this.autoplay = true;
			},
			//获取商品评价
			async getcommentList() {
				const {
					status,
					data
				} = await this.$request('SmallProgramApi/OrderEvaluate/getGoodsEvaluate', {
					goods_id: this.goods_id
				})
				if (status == 1) {
					this.commentInfo = data.list;
					this.total = data.total;
				}
			},
			// 跳转到评价列表页
			toComment() {
				uni.navigateTo({
					url: '/pages/order/commentList/comment?goods_id=' + this.goods_id
				});
			},

			//立即购买
			buynow() {
				if (!this.ischecknum) {
					this.Specifications()
					return;
				}
				if (this.Stock <= 0) {
					uni.showToast({
						title: '该商品库存不足',
						icon: 'none'
					});
					return false;
				}

				if (this.skuList && this.skuDetailList) {
					if (this.selectSkuDetailId == -1) {
						uni.showToast({
							title: '请选择商品规格',
							icon: 'none'
						});
						return false;
					}
				} //去支付					
				var details = this.details;
				details.num = this.buyNum;

				if (this.details.attribute_state == 2) {
					details.sku_id = this.selectSkuDetailId;
					var sku = this.shopItemInfo[this.selectArr.join(',')];
					details.sku_name = sku.name;
					details.advance_price = sku.advance_price;
					details.earnest_price = sku.earnest_price;
					details.arrive_price = sku.arrive_price;
					details.goods_img = sku.goods_img;
				} else {
					details.sku_id = '';
					details.sku_name = '';
				}

				uni.setStorageSync('advanceDetails', details);
				uni.navigateTo({
					url: '../advanceSettlement/advanceSettlement'
				});
			},
		}
	};
</script>
<style>
	@import "./advanceDetails.css";

	.myvideo {
		width: 100%;
		height: 100%;
	}
</style>
